package com.et.machine

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.et.logger.ELog
import com.et.machine.convert.size
import com.et.machine.service.StableService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Suppress("DEPRECATION")
class MainActivity : AppCompatActivity() {

    private val viewModel: MainViewModel by lazy {
        ViewModelProvider(this).get(MainViewModel::class.java)
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        getExternalFilesDir("log")?.also {
            ELog.init(it)
        }
        Intent(this, StableService::class.java).also {
            startService(it)
        }

        CoroutineScope(Dispatchers.IO).launch {
            viewModel.init(applicationContext)
        }

        val display = this.windowManager.defaultDisplay
        display?.getSize(size)

    }
}